package com.zidian.study.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zidian.student.trucks.R;
import com.zidian.study.bean.PrizeRecordBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by GongCheng on 2017/1/13.
 */

public class PrizeRecordAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private List<PrizeRecordBean.DataBean> data;
    private PrizeRecordBean.ChangeBean changeBean;
    private static final String[] PRIZE_LEVEL = {"S级礼物", "A级礼物", "B级礼物", "C级礼物", "D级礼物"};

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_prize_record, parent, false);

        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ItemViewHolder) {
            //TODO 判断奖品领取状态
            if (data.get(position).getPrizeType() == 1) {
                ((ItemViewHolder) holder).isGetPrize.setBackgroundResource(R.drawable.bg_do_get_prize);
                ((ItemViewHolder) holder).isGetPrize.setTextColor(Color.parseColor("#ffffff"));
                ((ItemViewHolder) holder).isGetPrize.setText("已领取");
            } else {
                ((ItemViewHolder) holder).isGetPrize.setBackgroundResource(R.drawable.bg_get_prize);
                ((ItemViewHolder) holder).isGetPrize.setTextColor(Color.parseColor("#e84e40"));
                ((ItemViewHolder) holder).isGetPrize.setText("未领取");
            }
            ((ItemViewHolder) holder).prizeNameTv.setText(PRIZE_LEVEL[data.get(position).getPrizeNumber() - 1]);
            ((ItemViewHolder) holder).lotteryPrizeTime.setText(data.get(position).getWinningTime());
            ((ItemViewHolder) holder).getPrizePlaceTv.setText("兑奖地点： " + changeBean.getChangeAddress());
            ((ItemViewHolder) holder).getPrizeTimeTv.setText("兑奖时间： " + changeBean.getChangeTime());
        }
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public void setData(PrizeRecordBean prizeRecordBeen) {
        data = prizeRecordBeen.getData();
        changeBean = prizeRecordBeen.getChange();
        notifyDataSetChanged();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.prize_name_tv)
        TextView prizeNameTv;
        @Bind(R.id.lottery_prize_time)
        TextView lotteryPrizeTime;
        @Bind(R.id.get_prize_time_tv)
        TextView getPrizeTimeTv;
        @Bind(R.id.get_prize_place_tv)
        TextView getPrizePlaceTv;
        @Bind(R.id.is_get_prize)
        TextView isGetPrize;

        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
